import React, { useState } from 'react'

export default function Index() {
    const [count, setCount] = useState(4)
    const [teacher, setName] = useState({ name: '小a', age: 18 })
    const handleClick = () => {
        setCount(() => {
            if (count < 3) {
                return count + 1
            } else {
                return count - 1
            }
        })
    }
    const handleChangeName = () => {
        setName(() => {
            return {
                ...teacher,
                name: '小李'
            }
        })
    }
    return (
        <div>
            <p>{count}</p>
            <button onClick={handleClick}>复杂情况</button>
            <button onClick={() => setCount(count + 1)}>简单情况</button>
            <div>
                <p>{teacher.name}</p>
                <p>{teacher.age}</p>
            </div>
            <button onClick={handleChangeName}>引用类型</button>
        </div>
    )
}
